<template>
    <div>
<h1>添加电子汇券信息</h1>
<table class="table table-bordered" border="1">
    <tr>
        <td>电子汇券标题</td>
        <td><input type="text" v-model="ad.bill_Tittle"></td>
    </tr>


    <tr>
        <td>电子汇券颜色</td>
        <td><input type="text" v-model="ad.bill_ys"></td>
    </tr>


    <tr>
        <td>电子汇券库存</td>
        <td><input type="text" v-model="ad.bill_Color"></td>
    </tr>


    
    <tr>
        <td>每人限邻</td>
        <td><input type="text" v-model="ad.bill_Use"></td>
    </tr>

    
    <tr>
        <td>开始日期</td>
        <td><input type="date" v-model="ad.bill_StarTime"></td>
    </tr>

    
    <tr>
        <td>结束日期</td>
        <td><input type="date" v-model="ad.bill_EndTime"></td>
    </tr>

    <tr>
        <td>客服电话</td>
        <td><input type="text" v-model="ad.bill_Pone"></td>
    </tr>

    <tr>
        <td>电子汇券要求</td>
        <td><select v-model="ad.shop_id">
            <option value="0">代金券</option>
            <option value="1">折扣券</option>
            <option value="2">兑换券</option>
        </select></td>
    </tr>


    <tr v-show="ad.shop_id==2">
        <td>使用须知（兑换券才有）</td>
        <td><input type="text" v-model="ad.bill_Precautions"></td>
    </tr>

    <tr v-show="ad.shop_id==1">
        <td>折扣(折扣券才有)</td>
        <td><input type="text" v-model="ad.bill_Discont"></td>
    </tr>

    <tr v-show="ad.shop_id==1">
        <td>适用业务(折扣券才有)</td>
        <td><input type="text" v-model="ad.bill_Business"></td>
    </tr>

    <tr v-show="ad.shop_id==0">
        <td>代金金额（代金券才有）</td>
        <td><input type="text" v-model="ad.bill_Money"></td>
    </tr>

  
    <tr>
        <td>所属门店</td>
        <td><select v-model="ad.bill_type">
            <option :value="0">请选择</option>
            <option v-for="item in xs" :value="item.shop_id">{{ item.shop_name }}</option>
        </select></td>
    </tr>


    <tr>
        <td></td>
        <td><input type="button" value="注册" @click="pdad"></td>
    </tr>

</table>
    </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from "vue";
import axios from "axios";

const xs=ref([{


shop_id: 0,
shop_name: "",
shop_Branchname: "",
shop_Address: "",
shop_pone: "",
shop_zt: true,
shop_js: "",
shop_Nptic: "",
jtxx: "",
shop_Img: ""


}])

const dbxs=()=>{
axios.get('https://localhost:7268/api/md/mendianshow')

.then(res=>{

    xs.value=res.data;
    
})
.then(error=>{


   console.log(error) 
})




}





onMounted(()=>{

    dbxs();

})





const ad=ref({
    bill_id: 0,
  bill_Tittle: "",
  bill_ys: "",
  bill_Color: "",
  bill_Use: "",
  bill_StarTime: "2024-10-28T07:34:17.805Z",
  bill_EndTime: "2024-10-28T07:34:17.805Z",
  bill_Pone: "",
  bill_Precautions: "",
  bill_Discont: 0,
  bill_Business: "",
  bill_Money: 0,
  bill_type: 0,
  shop_id: 0

})

const pdad=()=>{

if(ad.value.bill_Tittle=="")
{

alert('电子汇券标题不能为空');
return ;

}
if(Number(ad.value.bill_Use)<1)
{

alert('没人限领必须大于0张')
return;
}


if(ad.value.bill_Pone.length!=11  )

{

alert('手机格式不对')
return;
}



axios.post('https://localhost:7268/api/hq/addSearchTittle',ad.value)
.then(res=>{
if(res.data==-1)
{
alert('电子汇券名称已经存在 ');
return;

}
if(res.data>0)
{

alert('注册成功')

}
else{

    alert('注册失败')
}

})
.catch(error=>{

console.log(error);

})




}
</script>

<style scoped>

</style>